package Hot100;

import java.util.HashMap;

public class twoSum {
    public static void main(String[] args) {
        int[] nums = {3,3};
        int target = 6;
        int[] index = twoSum(nums,target);
        for (int i = 0; i < 2; i++) {
            System.out.println(index[i]);
        }


    }
    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> HashMap = new HashMap<>();
        int[] index = new int[2];
        for (int i = 0; i < nums.length; i++) {
            if(HashMap.containsKey(target - nums[i])){
                index[0] = i;
                index[1] = HashMap.get(target - nums[i]).intValue();
                break;
            }
            HashMap.put(nums[i],i);
        }
        return index;
    }
}
